<template>
  <div id="sceneexamine-map" style="width:100%;height:658px;"></div>
  <!--地图导出测试方法1-->
  <!--<a id="image-download" download="map.png"></a>-->
  <!--地图导出测试方法2-->
  <!--<a id="export-png" class="btn" download="map.png"><i class="icon-download">地图导出(暂支持非IE内核浏览器)</i></a>
  <a id="manypng" class="btn" download="map.png"><i class="icon-download" > Download many</i></a>-->
  <!-- width可以为100%，但是height必须是一个确定的值 -->
  <div id="sceneexamine-mapDiv" class="ol-popup">
    <!-- 显示控件 -->
    <div id="sceneexamine-setDivPosition"  class="init-setDivPosition">
      <!-- 切换卫星和街道地图 -->
      <p @click="switchMap" class="init-setDivPosition-selected">
        <template v-if="switchMapBool==false">
          <img src="@/assets/map/image/weixing-b.png" title="切换卫星地图"><br/><span>卫星图</span>
        </template>
        <template v-else>
          <img src="@/assets/map/image/jiedao-b.png" title="切换街道地图"><br/><span>街道图</span>
        </template>
      </p>
      <!-- 返回主界面 -->
      <p @click="zoomDefaultPosition" :class="{ 'init-setDivPosition-selected': zoomDefaultPositionBool==true }">
        <img src="@/assets/map/image/newImage/home.png" title="返回主界面"><br/><span>主界面</span>
      </p>
      <!-- 显示工具箱 -->
      <p @click="showHideToolsBoxDiv" :class="{ 'init-setDivPosition-selected': showHideToolsBox==false }">
        <template v-if="showHideToolsBox">
          <img src="@/assets/map/image/tools.png" title="打开工具箱"><br/><span>工具箱</span>
        </template>
        <template v-else>
          <img src="@/assets/map/image/tools.png" title="关闭工具箱"><br/><span>工具箱</span>
        </template>
      </p>
      <!-- 任务接口 -->
      <p @click="showHideTaskDiv" :class="{ 'init-setDivPosition-selected': showHideTask==false }">
        <img title="新建任务" src="@/assets/map/image/hf_rxdw_r.png"><br/>
        <span id="sceneexamine-setTaskDiv-span">新建任务</span>
      </p>
      <!-- 是否显示调研点 -->
      <p @click="querySurveyList" :class="{ 'init-setDivPosition-selected': showHideSurveyBool==false }">
        <template v-if="showHideSurveyBool">
          <img src="@/assets/map/image/fwdisplay.png" title="显示调研点"><br/><span style="border:0;font-size: 12px;">显示调研点</span>
        </template>
        <template v-else>
          <img src="@/assets/map/image/fwhide.png" title="隐藏调研点"><br/><span style="border:0;font-size: 12px;">隐藏调研点</span>
        </template>
      </p>
    </div>
    <!-- 任务接口 -->
    <div id="sceneexamine-taskDiv" class="init-TaskDiv">
      <p @click="mapDrawTaskPolygon" :class="{ 'init-setDivPosition-selected': showHideDrawTaskBool }"><span>地图圈选工作区域</span></p>
      <p @click="xzqhSelectTaskPolygon" style="margin-top: 16px;"><span>行政区划选择工作区域</span></p>
      <p @click="importTaskPolygon" style="margin-top: 16px;"><span style="border:0;">导入工作区域</span></p>
    </div>
    <!-- 工具箱 -->
    <div id="sceneexamine-ToolsBoxDiv" class="init-ToolsBoxDiv">
      <p @click="measureToolBox" :class="{ 'init-setDivPosition-selected': showHideMeasureTool==false }">
        <template v-if="showHideMeasureTool">
          <img title="开启测量工具" src="@/assets/map/image/cel.png"><br/><span>测量</span>
        </template>
        <template v-else>
          <img title="关闭测量工具" src="@/assets/map/image/cel.png"><br/><span>测量</span>
        </template>
      </p>
      <p @click="positionToolBox" :class="{ 'init-setDivPosition-selected': showHidePositionTool==false }">
        <template v-if="showHidePositionTool">
          <img title="开启定位工具" src="@/assets/map/image/dingw.png"><br/><span style="border:0;">定位</span>
        </template>
        <template v-else>
          <img title="关闭定位工具" src="@/assets/map/image/dingw.png"><br/><span style="border:0;">定位</span>
        </template>
      </p>
    </div>
    <!-- 所有工具 -->
    <div id="sceneexamine-AllToolsDiv" class="init-AllToolsDiv">
      <!-- 测量工具 -->
      <div id="sceneexamine-MeasureToolsDiv" class="init-AllToolsDivFloat">
        <p @click="measureDistance" :class="{ 'init-setDivPosition-selected': measureDistanceBool==false }">
          <template v-if="measureDistanceBool">
            <img src="@/assets/map/image/jul.png" title="测量距离（在地图上单击鼠标左键绘制折线，双击完成测量）"><br/><span>测量距离</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/jul.png" title="测量距离（在地图上单击鼠标左键绘制折线，双击完成测量）"><br/><span>测量距离</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="measureArea" :class="{ 'init-setDivPosition-selected': measureAreaBool==false }">
          <template v-if="measureAreaBool">
            <img src="@/assets/map/image/mianj.png" title="测量面积（在地图上单击鼠标左键绘制多边形，双击完成测量）"><br/><span>测量面积</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/mianj.png" title="测量面积（在地图上单击鼠标左键绘制多边形，双击完成测量）"><br/><span>测量面积</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="stopMeasure" :class="{ 'init-setDivPosition-selected': stopMeasureBool==false }">
          <template v-if="stopMeasureBool">
            <img src="@/assets/map/image/jshz.png" title="取消测量距离或测量面积操作"><br/><span>结束测量</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/jshz.png" title="取消测量距离或测量面积操作"><br/><span>结束测量</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="clearMeasure" :class="{ 'init-setDivPosition-selected': clearMeasureBool==false }">
          <template v-if="clearMeasureBool">
            <img src="@/assets/map/image/qux.png" title="清空全部测量结果"><br/><span>清空结果</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/qux.png" title="清空全部测量结果"><br/><span>清空结果</span>
          </template>
        </p>
      </div>
      <!-- 定位工具 -->
      <div id="sceneexamine-MousePositionDiv">
        <span><img class="init-jingd" src="@/assets/map/image/jingd.png" title="鼠标左键在地图上点击位置的经度值"></span>
        <input id="sceneexamine-MousePositionLon" type="text" value="">
        <span><img class="init-weid" src="@/assets/map/image/weid.png" title="鼠标左键在地图上点击位置的纬度值"></span>
        <input id="sceneexamine-MousePositionLat" type="text" value="">
        <p @click="clearPosition" :class="{ 'init-setDivPosition-selected': clearPositionBool==false }">
          <template v-if="clearPositionBool">
            <img src="@/assets/map/image/qux.png" title="清空全部定位点图标"><br/><span>清空结果</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/qux.png" title="清空全部定位点图标"><br/><span>清空结果</span>
          </template>
        </p>
        <p class="init-AllToolsDiv-split"></p>
        <p @click="addPosition" :class="{ 'init-setDivPosition-selected': addPositionBool==false }">
          <template v-if="addPositionBool">
            <img src="@/assets/map/image/dingwd.png" title="根据经纬度值在地图上添加定位点图标"><br/><span>添加定位点</span>
          </template>
          <template v-else>
            <img src="@/assets/map/image/dingwd.png" title="根据经纬度值在地图上添加定位点图标"><br/><span>添加定位点</span>
          </template>
        </p>
      </div>
    </div>
    <!-- 弹出窗口 -->
    <!--<div id="sceneexamine-popup" class="new-ol-popup">
      <a href="#" id="sceneexamine-popup-closer" class="new-ol-popup-closer"></a>
      <div id="sceneexamine-popup-content"></div>
    </div>-->
    <!-- 右键菜单 -->
    <div id="sceneexamine-contextMenuDiv" class="init-contextMenuDiv">
      <div id="sceneexamine-leftContextMenuDiv">
        <ul>
          <li id="sceneexamine-newTaskContextMenuLi" @click="mapNewTask">
            <span><img style='width:1px;' src=''>&nbsp;新建任务&nbsp;&nbsp;</span>
          </li>
          <li id="sceneexamine-editAreaContextMenuLi" @click="editPolygon">
            <span><img style='width:1px;' src=''>&nbsp;修改区域&nbsp;&nbsp;</span>
          </li>
          <li id="sceneexamine-drawEndTaskContextMenuLi" @click="saveEditPolygon">
            <span><img style='width:1px;' src=''>&nbsp;完成修改&nbsp;&nbsp;</span>
          </li>
          <li id="sceneexamine-delAreaContextMenuLi" @click="deletePolygon">
            <span><img style='width:1px;' src=''>&nbsp;删除区域&nbsp;&nbsp;</span>
          </li>
        </ul>
      </div>
    </div>
    <!-- 右键菜单 -->
    <div id="sceneexamineEx-contextMenuDiv" class="init-contextMenuDiv">
      <div id="sceneexamine-leftContextMenuDiv2">
        <ul>
          <li id="sceneexamine-newMapSurveyContextMenuLi" @click="newMapSurvey">
            <span><img style='width:1px;' src=''>&nbsp;新建调研点&nbsp;&nbsp;</span>
          </li>
          <!--<li id="sceneexamine-modifyAreaContextMenuLi" @click="editPolygon">
            <span><img style='width:1px;' src=''>&nbsp;修改区域&nbsp;&nbsp;</span>
          </li>
          <li id="sceneexamine-endDrawTaskContextMenuLi" @click="saveEditPolygon">
            <span><img style='width:1px;' src=''>&nbsp;完成修改&nbsp;&nbsp;</span>
          </li>-->
          <li id="sceneexamine-modifyContextMenuLi" @click="mapUpdTask">
            <span><img style='width:1px;' src=''>&nbsp;修改任务&nbsp;&nbsp;</span>
          </li>
          <li id="sceneexamine-deleteContextMenuLi" @click="mapDelTask">
            <span><img style='width:1px;' src=''>&nbsp;删除任务&nbsp;&nbsp;</span>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
import '@/assets/map/ol/ol.css';
import { getProjection,getResolutions,getTiandituVecMap,getTiandituVecText,getTiandituImgMap,getTiandituImgText,
  getRESTLayer,getVectorTileLayer,iServerHttp } from "@/map/projMap.js";
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import VectorLayer from 'ol/layer/Vector';
import {Cluster, Vector as VectorSource, XYZ} from 'ol/source'
import {Control, defaults as defaultControls} from 'ol/control';
import Overlay from 'ol/Overlay';
import WKT from 'ol/format/WKT';
import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
import Polygon from 'ol/geom/Polygon';
import LineString from 'ol/geom/LineString';
import {Fill, Stroke, Style, Icon, Circle,Text} from 'ol/style';
import {Select, Draw, Modify, Snap, Translate} from 'ol/interaction';
import {getArea, getLength} from 'ol/sphere';
import {unByKey} from 'ol/Observable';
import * as olExtent from 'ol/extent';
import {createBox} from 'ol/interaction/Draw';
import {boundingExtent} from 'ol/extent';
import { TileSuperMapRest,Logo,QueryByGeometryParameters,QueryService } from '@supermap/iclient-ol';
import dingweiImg from '@/assets/map/image/newImage/blueMarker.png';
//地图空间分析
import {getPointsDistance} from "@/map/taskmanage/sceneexamine/mapUtil.js";

export default {
  name: "SceneexamineMap",
  components: {

  },
  props:{
    allListData: {//任务列表
      type:Array,
      required:true,
      default:[]
    },
    isSaveMapPolygon: {//是否保存区域
      type:Boolean,
      required:true,
      default:false
    },
    surveyList: {//调研点列表
      type:Array,
      required:true,
      default:[]
    },
    districtTreeList: {//行政区划树列表
      type:Array,
      required:true,
      default:[]
    },
    taskRegionResultNameCodeList: {//地图圈选查询行政区划结果列表
      type:Array,
      required:false,
      default:[]
    },
    importShpTxtWkt:{//导入任务区域
      type:String,
      required:false,
      default:""
    }
  },
  emits:["xzqhSelect","mapShowTask","mapGetSurvey","mapNewTask","mapUpdTask","mapDelTask","newMapSurvey","mapLoading","getSurveyList","queryTaskRegionNameCodeListByGeomText","importShpTxt"],
  data() {
    return {
      str: "sceneexamine",
      map: null,
      projection4490:null,
      url: "https://iserver.supermap.io/iserver/services/map-china400/rest/maps/China_4490",//中国地图
      center: [105, 34],
      zoom: 4,
      mapLoadingBool:false,//是否正在查询参数
      zoomDefaultPositionBool:true,//显示主界面
      switchMapBool:false,//切换地图
      layer1:null,//天地图街道图
      layer2:null,
      layer3:null,//天地图卫星图
      layer4:null,
      draw:null,//矢量绘制
      snap:null,
      select:null,
      modify:null,
      drag:null,
      source:null,//矢量绘制图层数据
      measureSource:null,//测量结果图层数据
      measure:null,//测量工具
      sketch:null,
      helpTooltipElement:null,
      helpTooltip:null,
      measureTooltipElement:null,
      measureTooltip:null,
      measureTooltipArray:[],//全部测量结果Overlay数组
      showHideMeasureTool:true,//显示|隐藏测量工具
      measureDistanceBool:true,
      measureAreaBool:true,
      stopMeasureBool:true,
      clearMeasureBool:true,
      showHidePositionTool:true,//显示|隐藏定位工具
      addPositionBool:true,
      clearPositionBool:true,
      popupInfoLayer:null,//弹出窗口
      newContextMenu:null,//新建任务右键菜单
      taskContextMenu:null,//修改任务右键菜单
      showHideTask:true,
      showHideToolsBox:true,
      taskArea:null,//新建任务参数--面积
      taskRegion:null,//新建任务参数--经纬度范围
      parentdistrictList:[],//新建任务参数--行政区划
      groupDataList:[],//任务列表数据
      taskVectorLayer:null,//任务列表区域图层
      selectTaskRow:null,
      //查询省市县是否完成参数
      queryProvinceBool:false,
      queryCityBool:false,
      queryProCityBool:false,//省会城市查询完毕参数
      queryAreaBool:false,
      queryDrawAreaBool:false,//绘制区域点查询完毕参数
      queryDrawAreaPointCount:0,//绘制区域点数量
      //addressMatchService:null,//地址匹配
      addressUrl:"https://iserver.supermap.io/iserver/services/addressmatch-Address/restjsr/v1/address",
      selectFeature:null,//选中要素
      showHideSurveyBool:true,//是否显示调研点列表
      surveyVectorLayer:null,//全部调研点图层
      parentdistrictNameList:[],//区域查询行政区划名称列表
      parentdistrictCodeList:[],//区域查询行政区划编码列表
      districtTreeDataList:[],//行政区划树列表
      allDataList:[],//全部调研点数据列表
      showHideDrawTaskBool:false,//停止地图圈选工作区域
      drawAreaFeature:null,//地图圈选要素
      shpTxtWktGeom:"",//导入任务区域wkt
    }
  },
  watch: {
    allListData: {
      handler: function(newVal,oldVal){
        this.groupDataList = newVal;
        //if(newVal!=oldVal){
          this.showGroupData();
        //}
      },
      immediate:true
    },
    isSaveMapPolygon: {
      handler: function(newVal,oldVal){
        if(newVal){
          //保存任务区域事件
          this.saveMapTaskEvent();
        }
      },
      immediate:true
    },
    surveyList: {
      handler: function(newVal,oldVal){
        this.allDataList = newVal;
        //显示调研点列表
        this.showSurveyList();
      },
      immediate:true
    },
    districtTreeList: {
      handler: function(newVal,oldVal){
        //行政区划树列表
        this.districtTreeDataList = newVal;
      },
      immediate:true
    },
    taskRegionResultNameCodeList: {//地图圈选查询行政区划结果列表
      handler: function(newVal,oldVal){
        this.queryDrawAreaNewResult(newVal);//新查询绘制区域经纬度任务地区
      },
      immediate:true
    },
    importShpTxtWkt:{//导入任务区域
      handler: function(newVal,oldVal){
        if(newVal){
          this.importShpTxtWktGeom(newVal);//导入任务区域
        }
      },
      immediate:true
    },
  },
  created() {

  },
  mounted() {
    console.log("mounted");
    let that = this;
    //地图异步加载
    this.$nextTick(function(){
      console.log('地图异步加载');
      //地图异步加载
      setTimeout(() => {
        //初始化地图信息
        that.initMap();
        //显示任务区域
        that.showGroupData();
      }, 200);
    });
  },
  beforeCreate() {//生命周期创建之前
    console.log("beforeCreate");
  },
  beforeMount() {//生命周期挂载之前
    console.log("beforeMount");
  },
  beforeUpdate() {//生命周期更新之前
    console.log("beforeUpdate");
  },
  updated() {//生命周期更新之后
    console.log("updated");
  },
  beforeDestroy() {//生命周期销毁之前
    console.log("beforeDestroy");
  },
  destroyed() {//生命周期销毁完成
    this.map = null;
    console.log("销毁地图");
  },
  activated() {//如果页面有keep-alive缓存功能激活，这个函数会触发
    console.log("activated-"+this.str);
    //自动获取地图div高度
    this.autodivheight();
    //浏览器窗口发生变化时同时变化DIV高度
    window.onresize=this.autodivheight;
  },
  deactivated() {//如果页面有keep-alive缓存功能停用，这个函数会触发
    console.log("deactivated-"+this.str);
    //取消浏览器窗口发生变化时同时变化DIV高度事件
    window.onresize = null;
  },
  methods: {
    initMap() {
      debugger;
      let that = this;
      let mapStr = this.str;
      let targetMap = document.getElementById(mapStr+"-map");
      if(targetMap.innerHTML!=""){
        console.log("清空targetMap");
      }
      targetMap.innerHTML = "";//清空
      //新建popup弹窗
      let targetDiv = document.getElementById(mapStr+"-mapDiv");
      let node = document.createElement("div");
      node.id = mapStr+"-popup";
      node.setAttribute("class","new-ol-popup");
      node.innerHTML = '<a href="#" id="'+mapStr+'-popup-closer" class="new-ol-popup-closer"></a>' +
          '<div id="'+mapStr+'-popup-content"></div>';
      targetDiv.appendChild(node);
      console.log("新建popup");
      this.mapLoadingBool = true;
      //自动获取地图div高度
      this.autodivheight();
      //浏览器窗口发生变化时同时变化DIV高度
      window.onresize=this.autodivheight;
      if(this.map){//避免重复加载地图
        console.log("避免重复加载地图");
        return;
      }
      console.log("初始化地图");
      //获取投影4490坐标系
      this.projection4490 = getProjection();
      //初始化地图信息
      this.map = new Map({
        target: targetMap.id,
        view: new View({
          center: this.center,
          maxZoom: 18,
          minZoom: 4,
          zoom: this.zoom,
          constrainResolution:true,//缩放地图可移动到最近的缩放级别（整数zoom级别）
          projection: 'EPSG:4490',
          // resolutions:getResolutions()
        })
      });
      //添加天地图图层
      this.layer1 = getTiandituVecMap();//fxpc天地图街道影像底图
      this.map.addLayer(this.layer1);
      this.layer2 = getTiandituVecText();//fxpc天地图街道地图注记
      this.map.addLayer(this.layer2);
      this.layer1.setZIndex(0);
      this.layer2.setZIndex(0);
      //任务区域图层
      this.taskVectorLayer = new VectorLayer({
        source: new VectorSource({
          wrapX: false
        }),
        projection: 'EPSG:4490'
      });
      this.map.addLayer(this.taskVectorLayer);
      this.taskVectorLayer.setZIndex(1);
      //矢量绘制图层
      this.source = new VectorSource({
        wrapX: false
      });
      let vectorLayer = new VectorLayer({
        source: that.source,
        projection: 'EPSG:4490'
      });
      this.map.addLayer(vectorLayer);
      vectorLayer.setZIndex(2);
      //测量结果图层
      this.measureSource = new VectorSource({
        wrapX: false
      });
      let measureLayer = new VectorLayer({
        source: that.measureSource,
        projection: 'EPSG:4490'
      });
      this.map.addLayer(measureLayer);
      measureLayer.setZIndex(2);
      //全部调研点图层--聚合
      this.clusterMarkers();
      //添加控件
      let info = new Control({element: document.getElementById(mapStr+'-mapDiv')});
      info.setMap(this.map);
      this.map.addControl(info);
      //弹出窗口
      let popupTarget = document.getElementById(mapStr+"-popup");
      if(popupTarget){
        this.popupInfoLayer = new Overlay({
          element: popupTarget,
          positioning: 'center-center'
        });
        this.map.addOverlay(this.popupInfoLayer);
        //显示弹出窗口
        document.getElementById(mapStr+"-popup").style.display="block";
        //关闭弹出事件
        document.getElementById(mapStr+"-popup-closer").onclick = function () {
          that.popupInfoLayer.setPosition(undefined);
          //隐藏弹出窗口
          document.getElementById(mapStr+"-popup").style.display="none";
        };
      }
      //右键菜单--新建任务
      this.newContextMenu = new Overlay({
        element: document.getElementById(mapStr+"-contextMenuDiv"),
        positioning: 'center-center'
      });
      this.map.addOverlay(this.newContextMenu);
      //显示右键菜单
      document.getElementById(mapStr+"-contextMenuDiv").style.display="block";
      //右键菜单--修改任务
      this.taskContextMenu = new Overlay({
        element: document.getElementById(mapStr+"Ex-contextMenuDiv"),
        positioning: 'center-center'
      });
      this.map.addOverlay(this.taskContextMenu);
      //显示右键菜单
      document.getElementById(mapStr+"Ex-contextMenuDiv").style.display="block";
      //右键菜单事件
      this.map.on('contextmenu', function(event){
        event.preventDefault();//屏蔽自带的右键事件
        let pixel = that.map.getEventPixel(event.originalEvent);
        let feature = that.map.forEachFeatureAtPixel(pixel,function(feature){
          //根据像素坐标获取右键选中的地图要素
          return feature;
        });
        if(feature && that.draw==null){
          //取消选中要素
          that.clearSelectFeature();
          //隐藏右键菜单
          that.hideContextMenu();
          let coordinate = that.map.getEventCoordinate(event.originalEvent);
          let temp = feature.getProperties();
          console.log(temp);
          if(temp.groupData!=undefined && temp.groupData!=null){//修改任务
            //选中要素
            that.selectFeature = feature;
            that.selectTaskRow = temp.groupData;//任务row
            //右键菜单--修改任务
            that.taskContextMenu.setPosition(coordinate);
          }else if(temp.area!=undefined && temp.area!=null){//新建任务
            if(temp.type=="导入任务区域"){
              //选中要素
              that.selectFeature = feature;
              //计算面积
              let area = temp.area;
              //设置返回值
              that.taskArea = area.toString();
              that.taskRegion = that.shpTxtWktGeom;
              that.parentdistrictList = temp.parentdistrictList;
              //设置选中样式
              let style = that.getSelectPolyonStyle();
              feature.setStyle(style);
              //右键菜单--新建任务
              that.newContextMenu.setPosition(coordinate);
            }else{//地图绘制区域
              let geometry = feature.getGeometry();
              //获取多边形区域信息
              if (geometry instanceof Polygon) {
                //选中要素
                that.selectFeature = feature;
                //计算面积
                let area = temp.area;
                //设置返回值
                that.taskArea = area.toString();
                let taskRegion = "";
                let pointArr = geometry.getCoordinates();
                if(pointArr[0]!=null && pointArr[0].length>0){
                  for(let i=0;i<pointArr[0].length;i++){
                    let lonlat = pointArr[0][i];
                    if(i>0){
                      taskRegion += ";";
                    }
                    taskRegion += lonlat[0] + ',' + lonlat[1];
                  }
                }
                that.taskRegion = taskRegion;
                that.parentdistrictList = temp.parentdistrictList;
                //设置选中样式
                let style = that.getSelectPolyonStyle();
                feature.setStyle(style);
                //右键菜单--新建任务
                that.newContextMenu.setPosition(coordinate);
              }
            }
          }
        }
      });
      //点击地图事件
      this.map.on('click', function(event){
        //隐藏右键菜单
        that.hideContextMenu();
        if(that.modify==null){//不在修改状态
          //取消选中要素
          that.clearSelectFeature();
        }
        //隐藏弹出窗口
        if(that.popupInfoLayer!=null){
          that.popupInfoLayer.setPosition(undefined);
        }
        let pixel = that.map.getEventPixel(event.originalEvent);
        let coordinate = that.map.getEventCoordinate(event.originalEvent);
        //判断定位工具是否开启状态
        if(that.showHidePositionTool==false){
          document.getElementById(mapStr+"-MousePositionLon").value = coordinate[0];
          document.getElementById(mapStr+"-MousePositionLat").value = coordinate[1];
        }
        let feature = that.map.forEachFeatureAtPixel(pixel,function(feature){
          //根据像素坐标获取右键选中的地图要素
          return feature;
        });
        if(feature && that.draw==null){
          let temp = feature.getProperties();
          if(temp.groupData!=undefined && temp.groupData!=null) {//修改任务
            //选中要素
            that.selectFeature = feature;
            that.selectTaskRow = temp.groupData;//任务row
            //显示任务
            that.mapShowTask();
          }
          //调研点聚合数据
          if(feature.get('features')!=null){
            let size = feature.get('features').length;
            if(size>0){//调研点
              temp = feature.get('features')[0].getProperties();
              if(temp.id!=undefined && temp.id!=null) {//调研点
                console.log("查看调研点详情："+temp.id);
                //设置弹窗内容
                that.setPopupContentSurvey(temp);
                if(that.popupInfoLayer!=null){
                  that.popupInfoLayer.setPosition(coordinate);
                }
              }
            }
          }
        }
      });
      //地图移动事件
      this.map.on('moveend', function (event) {
        let center = that.map.getView().getCenter();
        let zoom = that.map.getView().getZoom();
        if(center[0]!=that.center[0] || center[1]!=that.center[1] || zoom!=that.zoom){
          //设置主界面图标文字
          that.zoomDefaultPositionBool = false;
        }else{//主界面
          //设置主界面图标文字
          that.zoomDefaultPositionBool = true;
        }
      });
      //鼠标移动事件--测量工具
      this.map.on('pointermove', function (evt) {
        if (evt.dragging) {
          return;
        }
        if(that.measure!=null){
          let helpMsg = '点击开始绘制';

          if (that.sketch) {
            const geom = that.sketch.getGeometry();
            if (geom instanceof Polygon) {
              helpMsg = '点击继续绘制多边形';
            } else if (geom instanceof LineString) {
              helpMsg = '点击继续绘制折线';
            }
          }

          that.helpTooltipElement.innerHTML = helpMsg;
          that.helpTooltip.setPosition(evt.coordinate);

          that.helpTooltipElement.classList.remove('hidden');
        }
      });
      //鼠标移出事件--测量工具
      this.map.getViewport().addEventListener('mouseout', function () {
        if(that.measure!=null){
          that.helpTooltipElement.classList.add('hidden');
        }
      });
      //地址匹配
      //this.addressMatchService = new AddressMatchService(this.addressUrl);
      //地图缩放到权限位置
      this.zoomDefaultPosition();
    },
    autodivheight() {//自动获取div高度
      //获取浏览器窗口高度
      let winHeight = 0;
      if (window.innerHeight) {
        winHeight = window.innerHeight;
      } else if ((document.body) && (document.body.clientHeight)) {
        winHeight = document.body.clientHeight;
      }
      //通过深入Document内部对body进行检测，获取浏览器窗口高度
      if (document.documentElement && document.documentElement.clientHeight) {
        winHeight = document.documentElement.clientHeight;
      }
      //全屏时窗口高度:864px,地图div高度:658px
      let tempHeight = 864;
      let mapTempHeight = 658;
      let mapHeight = winHeight - tempHeight + mapTempHeight;
      //最小高度
      if(mapHeight < 525){
        mapHeight = 525;
      }
      //设置地图高度
      document.getElementById(this.str+"-map").style.height= mapHeight +"px";
      console.log("窗口高度："+winHeight+"地图高度："+mapHeight);
      //resize事件--刷新地图,确保地图不变形
      if(this.map){
        this.map.updateSize();
        console.log("resize事件--刷新地图,确保地图不变形");
      }
    },
    setPopupContentSurvey(temp){//设置弹窗内容
      let html = "";
      //html += "id："+temp.id;
      html += "调研点名称："+this.getTextFormat(temp.fieldSurveyName);
      let assignorName = this.getTextFormat(temp.assignorName);
      if(assignorName!=""){
        html += "<br/>指定填写人："+assignorName;
      }
      /*html += "<br/>地址："+temp.province;
      if(!(temp.province=="北京市" || temp.province=="天津市" || temp.province=="上海市" || temp.province=="重庆市")){
        html += temp.city;
      }
      html += temp.area;
      html += temp.township;*/
      html += "<br/>地址："+this.getTextFormat(temp.township);
      html += "<br/>经度："+this.getTextFormat(temp.longitude);
      html += "<br/>纬度："+this.getTextFormat(temp.latitude);
      html += "<br/>任务编号："+this.getTextFormat(temp.taskCode);
      html += "<br/>任务名称："+this.getTextFormat(temp.taskName);
      document.getElementById(this.str+'-popup-content').innerHTML = html;
      //显示弹出窗口
      document.getElementById(this.str+"-popup").style.display="block";
    },
    getTextFormat(str){//格式化文本内容
      if(str==null || str==undefined){
        str = "";
      }
      return str;
    },
    hideContextMenu(){//隐藏右键菜单
      //隐藏右键菜单
      this.newContextMenu.setPosition(null);
      this.taskContextMenu.setPosition(null);
    },
    //显示任务列表区域
    showGroupData(){
      if(this.taskVectorLayer!=null){
        this.taskVectorLayer.getSource().clear();//清空
        console.log("显示任务列表区域"+new Date());
        console.log("数据长度："+this.groupDataList.length);
        if(this.groupDataList!=null && this.groupDataList.length>0){
          let featureTmpArray = [];
          for(let i=0;i<this.groupDataList.length;i++){
            let groupData = this.groupDataList[i];
            let taskRegion = groupData.taskRegion;
            if(taskRegion!=null && taskRegion!=""){
              if(taskRegion.indexOf("MULTIPOLYGON")==-1){//地图绘制区域
                let coordinates = [];
                let arr = taskRegion.split(";");
                if(arr!=null && arr.length>0){
                  for(let j=0;j<arr.length;j++){
                    let lonlatStr = arr[j].split(",");
                    let lonlat = [];
                    lonlat.push(Number(lonlatStr[0]));
                    lonlat.push(Number(lonlatStr[1]));
                    coordinates.push(lonlat);
                  }
                }
                //多边形
                let featureTmp = new Feature({
                  geometry: new Polygon([coordinates])
                });
                //样式
                let style = this.getPolyonStyle("orange");
                featureTmp.setStyle(style);
                //设置属性
                featureTmp.setProperties({groupData: groupData});
                //添加任务区域
                // this.taskVectorLayer.getSource().addFeature(featureTmp);
                featureTmpArray.push(featureTmp);
              }else{//行政区划选择区域
                let all_coords_str = taskRegion.split(";");
                for(let i=0;i<all_coords_str.length;i++){
                  // console.log(all_coords_str[i]);
                  //读取WKT
                  let featureTmp = new WKT().readFeature(all_coords_str[i]);
                  //样式
                  let style = this.getPolyonStyle("orange");
                  featureTmp.setStyle(style);
                  //设置属性
                  featureTmp.setProperties({groupData: groupData});
                  //添加任务区域
                  // this.taskVectorLayer.getSource().addFeature(featureTmp);
                  featureTmpArray.push(featureTmp);
                  /*let coords_str = all_coords_str[i].split("MULTIPOLYGON (((")[1].split(")))")[0];
                  let geometries = coords_str.split(")), ((");
                  for (let k = 0;k < geometries.length;k++) {
                    let allPointsArr = [];
                    let __coords = geometries[k].split("), (");
                    for (let m = 0;m < __coords.length;m++) {
                      let _coords = __coords[m].split(", "), points = [];
                      for (let n = 0;n < _coords.length;n++) {
                        if(_coords[n]!=null && _coords[n]!=""){
                          let coord = _coords[n].split(" ");
                          let lon = Number(coord[0]), lat = Number(coord[1]);
                          let lonlat = [lon, lat];
                          points.push(lonlat);
                        }
                      }
                      allPointsArr.push(points);
                    }
                    //多边形
                    let featureTmp = new Feature({
                      geometry: new Polygon(allPointsArr)
                    });
                    //样式
                    let style = this.getPolyonStyle("orange");
                    featureTmp.setStyle(style);
                    //设置属性
                    featureTmp.setProperties({groupData: groupData});
                    //添加任务区域
                    this.taskVectorLayer.getSource().addFeature(featureTmp);
                  }*/
                }
              }
            }
          }
          //批量添加任务区域
          this.taskVectorLayer.getSource().addFeatures(featureTmpArray);
          console.log("完成显示任务列表区域"+new Date());
        }
        if(this.showHideSurveyBool==false) {//显示调研点
          this.getSurveyList();//查询抽样点调查列表
        }
      }
    },
    //切换地图
    switchMap(){
      if(this.switchMapBool){//显示街道图
        this.switchMapBool = false;
        //添加天地图图层
        if(this.layer1==null){
          this.layer1 = getTiandituVecMap();//fxpc天地图街道影像底图
          this.map.addLayer(this.layer1);
        }
        if(this.layer2==null){
          this.layer2 = getTiandituVecText();//fxpc天地图街道地图注记
          this.map.addLayer(this.layer2);
        }
        //显示街道图
        this.layer1.setVisible(true);
        this.layer2.setVisible(true);
        this.layer3.setVisible(false);
        this.layer4.setVisible(false);
        this.layer1.setZIndex(0);
        this.layer2.setZIndex(0);
      }else{//显示卫星图
        this.switchMapBool = true;
        if(this.layer3==null){
          this.layer3 = getTiandituImgMap();//fxpc天地图卫星影像底图
          this.map.addLayer(this.layer3);
        }
        if(this.layer4==null){
          this.layer4 = getTiandituImgText();//fxpc天地图卫星影像注记
          this.map.addLayer(this.layer4);
        }
        //显示卫星图
        this.layer1.setVisible(false);
        this.layer2.setVisible(false);
        this.layer3.setVisible(true);
        this.layer4.setVisible(true);
        this.layer3.setZIndex(0);
        this.layer4.setZIndex(0);
      }
    },
    //地图缩放到权限位置
    zoomDefaultPosition() {
      //刷新地图,确保地图不变形
      this.map.updateSize();
      this.map.getView().setCenter(this.center);
      this.map.getView().setZoom(this.zoom);
      this.zoomDefaultPositionBool = true;
    },
    //显示任务接口菜单
    showHideTaskDiv(){
      if(this.showHideTask){
        this.showHideTask = false;
        document.getElementById(this.str+"-taskDiv").style.display="block";
        document.getElementById(this.str+"-setTaskDiv-span").innerHTML="结束新建";
        //隐藏工具箱
        this.showHideToolsBox = true;
        document.getElementById(this.str+"-ToolsBoxDiv").style.display="none";
      }else{
        this.showHideTask = true;
        document.getElementById(this.str+"-taskDiv").style.display="none";
        document.getElementById(this.str+"-setTaskDiv-span").innerHTML="新建任务";
        //地图工具箱--结束新建
        this.setMapToolBox('StopDraw');
      }
    },
    //显示工具箱
    showHideToolsBoxDiv(){
      if(this.showHideToolsBox){
        this.showHideToolsBox = false;
        document.getElementById(this.str+"-ToolsBoxDiv").style.display="block";
      }else{
        this.showHideToolsBox = true;
        document.getElementById(this.str+"-ToolsBoxDiv").style.display="none";
      }
      //关闭全部工具
      this.closeAllToolsBox(null);
    },
    //关闭全部工具
    closeAllToolsBox(type){
      //关闭测量工具
      if(type!="MeasureTool" && this.showHideMeasureTool==false){
        this.showHideMeasureTool = true;
        let divId = this.str+"-MeasureToolsDiv";
        //隐藏
        document.getElementById(divId).style.display = "none";
        //清空测量结果
        this.clearMeasure();
        this.clearMeasureBool = true;
      }
      //关闭定位工具
      if(type!="PositionTool" && this.showHidePositionTool==false){
        this.showHidePositionTool = true;
        let divId = this.str+"-MousePositionDiv";
        //隐藏
        document.getElementById(divId).style.display = "none";
        //清空定位结果
        this.clearPosition();
      }
    },
    //地图圈选工作区域
    mapDrawTaskPolygon(){
      this.showHideDrawTaskBool = true;
      //地图工具箱
      this.setMapToolBox('Polygon');
    },
    //行政区划选择工作区域
    xzqhSelectTaskPolygon(){
      this.$emit("xzqhSelect",null);
    },
    //导入工作区域
    importTaskPolygon(){
      this.$emit("importShpTxt",null);
    },
    //显示任务详情
    mapShowTask(){
      let row = this.selectTaskRow;
      this.$emit("mapShowTask",row.id);
    },
    //显示调研点详情
    mapGetSurvey(){
      let row = this.selectTaskRow;
      this.$emit("mapGetSurvey",row.id);
    },
    //新建任务
    mapNewTask(){
      console.log(this.parentdistrictList);
      let temp = {
        taskArea:this.taskArea,
        taskRegion:this.taskRegion,
        parentdistrictList:this.parentdistrictList
      }
      this.$emit("mapNewTask",temp);
      //隐藏右键菜单
      this.hideContextMenu();
    },
    //修改任务
    mapUpdTask(){
      let row = this.selectTaskRow;
      this.$emit("mapUpdTask",row);
      //隐藏右键菜单
      this.hideContextMenu();
    },
    //删除任务
    mapDelTask(){
      let row = this.selectTaskRow;
      this.$emit("mapDelTask",row);
      //隐藏右键菜单
      this.hideContextMenu();
    },
    //修改区域
    editPolygon(){
      //地图工具箱--开启修改
      this.setMapToolBox('Modify');
      //隐藏右键菜单
      this.hideContextMenu();
    },
    //完成修改区域
    saveEditPolygon(){
      //隐藏右键菜单
      this.hideContextMenu();
      //地图工具箱--停止修改
      this.setMapToolBox('NotModify');
      //取消选中要素
      this.clearSelectFeature();
    },
    //删除区域
    deletePolygon(){
      //隐藏右键菜单
      this.hideContextMenu();
      if(this.selectFeature!=null) {
        let temp = this.selectFeature.getProperties();
        if(temp.groupData!=undefined && temp.groupData!=null) {//修改任务
          //移除选中要素区域
          this.taskVectorLayer.getSource().removeFeature(this.selectFeature);
        }else{//新建任务
          //移除选中要素区域
          this.source.removeFeature(this.selectFeature);
        }
      }
    },
    //新建调研点
    newMapSurvey(){
      //隐藏右键菜单
      this.hideContextMenu();
      let row = this.selectTaskRow;
      this.$emit("newMapSurvey",row);
    },
    mapLoading(msg){//地图查询Loading
      if(this.mapLoadingBool){
        this.$emit("mapLoading",msg);
      }
    },
    getSurveyList(){//查询抽样点调查列表
      this.$emit("getSurveyList",null);
    },
    saveMapTaskEvent(){//保存任务区域事件
      //删除区域
      this.deletePolygon();
    },
    //地图工具--测试地图打印功能
    toolsBoxPrintTest(){
      let that = this;
      //测试地图导出方法一
      /*this.map.once('rendercomplete', function () {
        const mapCanvas = document.createElement('canvas');
        const size = that.map.getSize();
        mapCanvas.width = size[0];
        mapCanvas.height = size[1];
        const mapContext = mapCanvas.getContext('2d');
        Array.prototype.forEach.call(
            //document.querySelectorAll('.ol-layer canvas'),
            document.querySelectorAll('#sceneexamine-map .ol-viewport .ol-layer canvas'),
            function (canvas) {
              if (canvas.width > 0) {
                const opacity = canvas.parentNode.style.opacity;
                mapContext.globalAlpha = opacity === '' ? 1 : Number(opacity);
                const transform = canvas.style.transform;
                // Get the transform parameters from the style's transform matrix
                const matrix = transform
                    .match(/^matrix\(([^\(]*)\)$/)[1]
                    .split(',')
                    .map(Number);
                // Apply the transform to the export map context
                CanvasRenderingContext2D.prototype.setTransform.apply(
                    mapContext,
                    matrix
                );
                mapContext.drawImage(canvas, 0, 0);
              }
            }
        );
        if (navigator.msSaveBlob) {
          // link download attribute does not work on MS browsers
          navigator.msSaveBlob(mapCanvas.msToBlob(), 'map.png');
        } else {
          const link = document.getElementById('image-download');
          link.crossOrigin = 'anonymous';
          link.href = mapCanvas.toDataURL();
          link.click();
        }
      });
      this.map.renderSync();*/


      //测试地图导出方法二
      /*let exportPNGElement = document.getElementById('export-png'); //导出图片功能项
      let manypng = document.getElementById('manypng'); //导出图片功能项
      if ('download' in exportPNGElement) {
        exportPNGElement.addEventListener('click', function (e) {
          that.map.once('postcompose', function (event) {debugger
            let canvas = event.context.canvas; //地图渲染容器
            exportPNGElement.href = canvas.toDataURL('image/png'); //导出图片
          });
          that.map.renderSync();
        }, false);
      } else {
        alert("浏览器不支持此导出地图图片功能！");
      }

      if ('download' in manypng) {
        manypng.addEventListener('click', function(e) {
          //  that.map.removeInteraction(draw);
          addInteraction();
          that.map.renderSync();
        },false);
      }

      let draw; // global so we can remove it later
      let source = new VectorSource();
      function addInteraction() {
        draw = new Draw({
          source: source,
          type: 'LineString',
          style: new Style({
            fill: new Fill({
              color: 'rgba(255, 255, 255, 0.2)'
            }),
            stroke: new Stroke({
              color: '#ffcc33',
              width: 2
            }),
            image: new Circle({
              radius: 7,
              fill: new Fill({
                color: '#ffcc33'
              })
            })
          }),
          maxPoints: 2,
          geometryFunction: createBox()//矩形框
        })

        that.map.addInteraction(draw);

        // that.map.values_.target='map2';

        function getXDis(e, number) {
          let min = undefined;
          let max = undefined;
          e.forEach(element => {
            if (min == undefined || element[number] < min) {
              min = element[number];
            }

            if (max == undefined || element[number] > max) {
              max = element[number];
            }
          });
          return [min+2, max - min-4];
        }

        let extent = [];
        draw.on('drawend',function(evt){
          let feature = evt.feature;console.log(feature);
          let ftarget = evt.target.a;
          let geometry=feature.getGeometry();
          let ext=geometry.getExtent();
          that.map.removeInteraction(draw);

          let r = that.map.getView().getResolutionForExtent(ext, that.map.getSize());//根据范围获取分辨率
          that.map.getView().setResolution(r);
          that.map.getView().setZoom(12);
          let centerone=olExtent.getCenter(ext);
          that.map.getView().setCenter(centerone);

          let canvas;
          let imageData;
          let canvas2;
          let coordinate=geometry.getCoordinates();
          that.map.once("postrender", function (e) {
            extent[0] = e.target.getPixelFromCoordinate(coordinate[0][0]);//转画布坐标
            extent[1] = e.target.getPixelFromCoordinate(coordinate[0][1]);
            extent[2] = e.target.getPixelFromCoordinate(coordinate[0][2]);
            extent[3] = e.target.getPixelFromCoordinate(coordinate[0][3]);

            let x_dx = getXDis(extent, 0);
            let y_dy = getXDis(extent, 1);

            that.map.once("postcompose", function(event) {
              canvas = event.context.canvas;
              let ctx2=canvas.getContext("2d");
              imageData = ctx2.getImageData(x_dx[0], y_dy[0], x_dx[1], y_dy[1]);
              let c=document.getElementById("sceneexamine-map");
              c.style.width=imageData.width+'px';
              c.style.height=imageData.height+'px';
              that.map.updateSize();//容器改变重新加载地图
            });
            that.map.once('rendercomplete',function(){//渲染完成
              canvas.toBlob(function (blob) {
                saveAs(blob, 'map.png');debugger
                $('#sceneexamine-map').css({
                  width:"100%",
                  height:"100%"
                });
                that.map.updateSize();//容器改变重新加载地图
              });
            });
          });
        });
      }*/
    },
    measureToolBox(){//测量工具Div
      let divId = this.str+"-MeasureToolsDiv";
      //关闭全部工具
      this.closeAllToolsBox("MeasureTool");
      if(this.showHideMeasureTool){
        this.showHideMeasureTool = false;
        //显示
        document.getElementById(divId).style.display = "block";
      }else{
        this.showHideMeasureTool = true;
        //隐藏
        document.getElementById(divId).style.display = "none";
      }
    },
    measureDistance(){//测距
      if(this.source!=null){
        //地图工具箱--开启测距
        this.setMapToolBox('MeasureDistance');
        //设置样式
        this.measureDistanceBool = false;
        this.measureAreaBool = true;
        this.stopMeasureBool = true;
        this.clearMeasureBool = true;
      }
    },
    measureArea(){//测面
      if(this.source!=null){
        //地图工具箱--开启测面
        this.setMapToolBox('MeasureArea');
        //设置样式
        this.measureAreaBool = false;
        this.measureDistanceBool = true;
        this.stopMeasureBool = true;
        this.clearMeasureBool = true;
      }
    },
    stopMeasure(){//停止测量
      if(this.source!=null){
        //地图工具箱--停止测量
        this.setMapToolBox('StopMeasure');
        //设置样式
        this.stopMeasureBool = false;
        this.measureDistanceBool = true;
        this.measureAreaBool = true;
        this.clearMeasureBool = true;
      }
    },
    clearMeasure(){//清空测量结果
      if(this.source!=null){
        //地图工具箱--清空测量结果
        this.setMapToolBox('ClearMeasure');
        //设置样式
        this.clearMeasureBool = false;
        this.measureDistanceBool = true;
        this.measureAreaBool = true;
        this.stopMeasureBool = true;
      }
    },
    positionToolBox(){//定位工具Div
      let divId = this.str+"-MousePositionDiv";
      //关闭全部工具
      this.closeAllToolsBox("PositionTool");
      if(this.showHidePositionTool){
        this.showHidePositionTool = false;
        //显示
        document.getElementById(divId).style.display = "block";
      }else{
        this.showHidePositionTool = true;
        //隐藏
        document.getElementById(divId).style.display = "none";
      }
    },
    addPosition(){//添加定位结果
      this.clearPositionBool = true;
      this.addPositionBool = false;
      //添加定位结果
      if(this.source!=null){
        let longitude = document.getElementById(this.str+"-MousePositionLon").value;
        let latitude = document.getElementById(this.str+"-MousePositionLat").value;
        //处理经纬度
        let lonlat = this.getLonLat(longitude,latitude);
        if(lonlat!=null){
          //点
          let featureTmp = new Feature({
            geometry: new Point(lonlat)
          });
          //样式
          let style = this.getPointStyle();
          featureTmp.setStyle(style);
          //设置属性
          featureTmp.setProperties({
            type:"position",
            longitude:longitude,
            latitude:latitude,
          });
          //添加定位点
          this.source.addFeature(featureTmp);
          //居中缩放
          this.map.getView().setCenter(lonlat);
          this.map.getView().setZoom(12);
        }
      }
    },
    clearPosition(){//清空定位结果
      this.clearPositionBool = false;
      this.addPositionBool = true;
      //地图工具箱--清空
      this.setMapToolBox("Clear");
    },
    //地图工具箱
    setMapToolBox(value) {
      let that = this;
      if (value === 'Clear') {//清空
        //清空
        that.source.clear();
        //停止绘制|修改|拖拽|选择
        clearInteraction();
      }else if (value === 'Point' || value === 'LineString' || value === 'Polygon' || value === 'Circle') {//开启绘制
        //点|线|面|圆绘制
        //开启绘制
        startDrawInteraction(value,false);
      }else if (value === 'FreeHandLineString' || value === 'FreeHandPolygon') {//开启绘制
        //手绘线|手绘面
        value = value.split("FreeHand")[1];
        //开启绘制
        startDrawInteraction(value,true);
      }else if (value === 'StopDraw') {//停止绘制
        //停止绘制
        stopDrawInteraction();
      }else if (value === 'Snap') {//开启捕捉
        //开启捕捉
        startSnapInteraction();
      }else if (value === 'NotSnap') {//停止捕捉
        //停止捕捉
        stopSnapInteraction();
      }else if (value === 'Modify') {//开启修改
        //开启修改
        startModifyInteraction();
      }else if (value === 'NotModify') {//停止修改
        //停止修改
        stopModifyInteraction();
        //停止选择
        stopSelectInteraction();
      }else if (value === 'Drag') {//开启拖拽
        //开启拖拽
        startDragInteraction();
      }else if (value === 'NotDrag') {//停止拖拽
        //停止拖拽
        stopDragInteraction();
      }else if (value === 'Select') {//开启选择
        //开启选择
        startSelectInteraction();
      }else if (value === 'NotSelect') {//停止选择
        //停止选择
        stopSelectInteraction();
      } else if (value === 'MeasureDistance') {//开启测距
        //开启测距
        startMeasureInteraction('LineString');
      } else if (value === 'MeasureArea') {//开启测面
        //开启测面
        startMeasureInteraction('Polygon');
      } else if (value === 'StopMeasure') {//停止测量（测距|测面）
        //停止测量
        stopMeasureInteraction();
      } else if (value === 'ClearMeasure') {//清空测量结果
        //停止测量
        stopMeasureInteraction();
        //清空测量结果
        clearMeasureResult();
      }

      //停止绘制|修改|拖拽|选择
      function clearInteraction() {
        //停止拖拽
        stopDragInteraction();
        //停止修改
        stopModifyInteraction();
        //停止选择
        stopSelectInteraction();
        //停止绘制
        stopDrawInteraction();
      }

      //停止捕捉
      function stopSnapInteraction(){
        if (that.snap) {
          that.map.removeInteraction(that.snap);
          that.snap = null;
        }
      }

      //开启捕捉
      function startSnapInteraction(){
        //停止捕捉
        stopSnapInteraction();
        //开启捕捉
        that.snap = new Snap({
          source: that.source
        });
        that.map.addInteraction(that.snap);
      }

      //停止拖拽
      function stopDragInteraction() {
        //停止拖拽
        if (that.drag) {
          that.map.removeInteraction(that.drag);
          that.drag = null;
        }
      }

      //开启拖拽
      function startDragInteraction() {
        //停止绘制
        stopDrawInteraction();
        //停止修改
        stopModifyInteraction();
        //开启选择
        startSelectInteraction();
        //停止拖拽
        stopDragInteraction();
        //开启拖拽
        that.drag = new Translate({
          features: that.select.getFeatures()
        });
        that.map.addInteraction(that.drag);
      }

      //停止修改
      function stopModifyInteraction() {
        //停止修改
        if (that.modify) {
          that.map.removeInteraction(that.modify);
          that.modify = null;
        }
      }

      //开启修改
      function startModifyInteraction() {
        //停止绘制
        stopDrawInteraction();
        //开启选择
        //startSelectInteraction();
        //停止修改
        stopModifyInteraction();
        //开启修改
        /*that.modify = new Modify({
          features: that.select.getFeatures()
        });*/
        that.modify = new Modify({
          source: that.source
        });
        that.map.addInteraction(that.modify);
      }

      //停止选择
      function stopSelectInteraction() {
        //停止选择
        if (that.select) {
          that.map.removeInteraction(that.select);
          that.select = null;
        }
      }

      //开启选择
      function startSelectInteraction() {
        //停止选择
        stopSelectInteraction();
        //开启选择
        that.select = new Select({
          wrapX: false
        });
        that.map.addInteraction(that.select);
      }

      //停止绘制
      function stopDrawInteraction() {
        //停止绘制
        if (that.draw) {
          that.map.removeInteraction(that.draw);
          that.draw = null;
        }
      }

      //开启绘制
      function startDrawInteraction(type,bool) {
        //停止拖拽
        stopDragInteraction();
        //停止修改
        stopModifyInteraction();
        //停止选择
        stopSelectInteraction();
        //停止绘制
        stopDrawInteraction();
        if(bool){//手绘线|手绘面
          that.draw = new Draw({
            source: that.source,
            type: type,
            snapTolerance: 20,
            freehand: true
          });
          that.map.addInteraction(that.draw);
        }else{//点|线|面|圆绘制
          that.draw = new Draw({
            source: that.source,
            type: type,
            snapTolerance: 20
          });
          that.map.addInteraction(that.draw);
          //绘制结束时触发的事件
          that.draw.on('drawend', function(e) {
            let geometry = e.feature.getGeometry();
            let pointArr = geometry.getCoordinates();
            //停止绘制
            stopDrawInteraction();
            that.showHideDrawTaskBool = false;//停止地图圈选工作区域
            //设置样式
            let style = that.getPolyonStyle("red");
            e.feature.setStyle(style);
            //计算面积
            if (geometry instanceof Polygon) {
              let area = getPolygonArea(geometry);
              //清空查询行政区划列表
              that.parentdistrictList = [];
              //清空区域查询行政区划名称列表
              that.parentdistrictNameList = [];
              //清空区域查询行政区划编码列表
              that.parentdistrictCodeList = [];
              //正在查询
              that.mapLoading("正在查询，请稍候...");
              //新查询绘制区域经纬度任务地区
              that.queryDrawAreaNew(e.feature);
              /*//几何查询--省值
              that.queryProvince(e.feature);
              //几何查询--省会市值
              that.queryProCenCity(e.feature);
              //几何查询--市值
              that.queryCity(e.feature);
              //几何查询--区县值
              that.queryArea(e.feature);
              //获取多边形面内的均匀点分布数组
              let allLonLatArr = that.getPolygonExtentPoints(geometry);
              //查询绘制区域经纬度点地址
              that.queryDrawArea(e.feature,allLonLatArr);*/
              //设置属性
              e.feature.setProperties({area: area});
            }
          });
        }
      }

      //计算面积
      function getPolygonArea (polygon) {
        // 这里一定要给坐标，和地图坐标保持一致，否则面积不准
        const area = getArea(polygon, {projection: 'EPSG:4490'})
        let output = Math.round((area / 1000000) * 100) / 100;//平方公里
        return output;
      }

      ////////////////////////////////////////////////////////////////////测量工具箱
      //格式化距离
      function formatLength(line) {
        const length = getLength(line, {projection: 'EPSG:4490'});
        let output;
        if (length > 100) {
          output = Math.round((length / 1000) * 100) / 100 + ' ' + 'km';
        } else {
          output = Math.round(length * 100) / 100 + ' ' + 'm';
        }
        return output;
      }

      //格式化面积
      function formatArea(polygon) {
        const area = getArea(polygon, {projection: 'EPSG:4490'});
        let output;
        if (area > 10000) {
          output = Math.round((area / 1000000) * 100) / 100 + ' ' + 'km<sup>2</sup>';
        } else {
          output = Math.round(area * 100) / 100 + ' ' + 'm<sup>2</sup>';
        }
        return output;
      }

      //创建新的提示tip
      function createHelpTooltip() {
        if (that.helpTooltipElement!=null) {
          that.helpTooltipElement.parentNode.removeChild(that.helpTooltipElement);
        }
        that.helpTooltipElement = document.createElement('div');
        that.helpTooltipElement.className = 'ol-tooltip hidden';
        that.helpTooltip = new Overlay({
          element: that.helpTooltipElement,
          offset: [15, 0],
          positioning: 'center-left',
        });
        that.map.addOverlay(that.helpTooltip);
      }

      //创建新的测量提示
      function createMeasureTooltip() {
        if (that.measureTooltipElement!=null) {
          that.measureTooltipElement.parentNode.removeChild(that.measureTooltipElement);
        }
        that.measureTooltipElement = document.createElement('div');
        that.measureTooltipElement.className = 'ol-tooltip ol-tooltip-measure';
        that.measureTooltip = new Overlay({
          element: that.measureTooltipElement,
          offset: [0, -15],
          positioning: 'bottom-center',
          stopEvent: false,
          insertFirst: false,
        });
        that.map.addOverlay(that.measureTooltip);
      }

      //开启测量工具
      function startMeasureInteraction(type) {
        //停止测量工具
        stopMeasureInteraction();

        console.log(type);
        //开启测量工具--绘制
        that.measure = new Draw({
          source: that.measureSource,
          type: type,
          style: new Style({
            fill: new Fill({
              color: 'rgba(255, 255, 255, 0.2)',
            }),
            stroke: new Stroke({
              color: 'rgba(0, 0, 0, 0.5)',
              lineDash: [10, 10],
              width: 2,
            }),
            image: new Circle({
              radius: 5,
              stroke: new Stroke({
                color: 'rgba(0, 0, 0, 0.7)',
              }),
              fill: new Fill({
                color: 'rgba(255, 255, 255, 0.2)',
              }),
            }),
          }),
        });
        that.map.addInteraction(that.measure);

        //创建新的测量提示
        createMeasureTooltip();
        //创建新的提示tip
        createHelpTooltip();

        let listener;
        that.measure.on('drawstart', function (evt) {
          //设置sketch
          that.sketch = evt.feature;

          let tooltipCoord = evt.coordinate;

          listener = that.sketch.getGeometry().on('change', function (evt) {
            const geom = evt.target;
            let output;
            if (geom instanceof Polygon) {
              output = formatArea(geom);
              tooltipCoord = geom.getInteriorPoint().getCoordinates();
            } else if (geom instanceof LineString) {
              output = formatLength(geom);
              tooltipCoord = geom.getLastCoordinate();
            }
            that.measureTooltipElement.innerHTML = output;
            that.measureTooltip.setPosition(tooltipCoord);
          });
        });
        //完成测量绘制
        that.measure.on('drawend', function () {
          that.measureTooltipElement.className = 'ol-tooltip ol-tooltip-static';
          that.measureTooltip.setOffset([0, -7]);
          //添加到数组
          that.measureTooltipArray.push(that.helpTooltip);
          //添加到数组
          that.measureTooltipArray.push(that.measureTooltip);
          //清空sketch
          that.sketch = null;
          //清空tooltip
          that.measureTooltipElement = null;
          createMeasureTooltip();
          unByKey(listener);
        });
      }

      //停止测量工具
      function stopMeasureInteraction() {
        //停止绘制
        stopDrawInteraction();
        //停止测量工具
        if (that.measure) {
          that.map.removeInteraction(that.measure);
          that.measure = null;
          //隐藏提示tip
          that.helpTooltipElement.classList.add('hidden');
          //移除测量提示
          if(that.helpTooltip!=null){
            that.map.removeOverlay(that.helpTooltip);
          }
          if(that.measureTooltip!=null){
            that.map.removeOverlay(that.measureTooltip);
          }
        }
      }

      //清空测量结果
      function clearMeasureResult(){
        if(that.measureSource!=null){
          //清空测量结果
          that.measureSource.clear();
          //清空测量结果提示数组
          if(that.measureTooltipArray.length>0){
            for(let i=0;i<that.measureTooltipArray.length;i++){
              that.map.removeOverlay(that.measureTooltipArray[i]);
            }
            that.measureTooltipArray = [];
          }
        }
      }
    },
    getPolyonStyle(color){//多边形样式
      let style = new Style({
        fill:new Fill({//填充样式
          color:"rgba(0,0,0,0)"
        }),
        stroke:new Stroke({//描绘
          width:2,//宽
          color:color
        })
      });

      return style;
    },
    getPointStyle(){//点图标样式
      let style = new Style({
        image: new Icon({
          src: dingweiImg,
          anchor: [0.5, 1]
        }),
      });

      return style;
    },
    getSelectPolyonStyle(){//选中要素样式
      let style = new Style({
        fill:new Fill({//填充样式
          color:"rgba(255,255,255,0.2)"
        }),
        stroke:new Stroke({//描绘
          width:2,//宽
          color:"rgba(30,144,255,1)"
        })
      });

      return style;
    },
    clearSelectFeature(){//取消选中要素
      if(this.selectFeature!=null){
        let temp = this.selectFeature.getProperties();
        if(temp.groupData!=undefined && temp.groupData!=null) {//修改任务
          let style = this.getPolyonStyle("orange");
          this.selectFeature.setStyle(style);
        }else if(temp.area!=undefined && temp.area!=null){//新建任务
          let style = this.getPolyonStyle("red");
          this.selectFeature.setStyle(style);
        }
        this.selectFeature = null;
      }
    },
    queryProvince(feature){//几何查询--省值
      let that = this;
      let polygon = feature.getGeometry();
      let resultArray = [];
      let param = new QueryByGeometryParameters({
        //queryParams: {name: "China_provincename_A_txt@China"},
        queryParams: {name: "China_Province_pl@China"},//省区域
        geometry: polygon
      });
      new QueryService(this.url).queryByGeometry(param, function (serviceResult) {
        let features = serviceResult.result.recordsets[0].features.features;
        if(features!=null && features.length!=null){
          for(let i=0;i<features.length;i++){
            let feature = features[i];
            let temp = feature.properties;
            //let province = temp.texts[0];
            let province = temp.NAME;
            //省市县名称处理
            province = that.setNameStr(province);
            that.parentdistrictNameList.push(province);
            let code = that.getProvinceCodeByName(province);//根据省名称获取省编码信息
            that.parentdistrictCodeList.push(code);
          }
        }
        //设置查询省市县是否完成参数
        that.queryProvinceBool = true;
        console.log("完成几何查询--省值");
        //判断省市县是否查询完毕
        if(that.queryProvinceBool && that.queryCityBool && that.queryProCityBool &&that.queryAreaBool && that.queryDrawAreaBool){
          //匹配省市县信息
          that.getProvinceCityArea(feature);
          //完成查询
          that.mapLoading(null);
        }
      });

      return resultArray;
    },
    queryProCenCity(feature){//几何查询--省会市值
      let that = this;
      let polygon = feature.getGeometry();
      let resultArray = [];
      let param = new QueryByGeometryParameters({
        queryParams: {name: "China_ProCenCity_pt@China"},
        geometry: polygon
      });
      new QueryService(this.url).queryByGeometry(param, function (serviceResult) {
        let features = serviceResult.result.recordsets[0].features.features;
        if(features!=null && features.length!=null){
          for(let i=0;i<features.length;i++){
            let feature = features[i];
            let temp = feature.properties;
            let code = temp.GNID;
            that.parentdistrictCodeList.push(code);
            let city = temp.NAME;
            //省市县名称处理
            city = that.setNameStr(city);
            that.parentdistrictNameList.push(city);
          }
        }
        //设置查询省市县是否完成参数
        that.queryProCityBool = true;
        console.log("完成几何查询--省会市值");
        //判断省市县是否查询完毕
        if(that.queryProvinceBool && that.queryCityBool && that.queryProCityBool && that.queryAreaBool && that.queryDrawAreaBool){
          //匹配省市县信息
          that.getProvinceCityArea(feature);
          //完成查询
          that.mapLoading(null);
        }
      });

      return resultArray;
    },
    queryCity(feature){//几何查询--市值(除省会城市)
      let that = this;
      let polygon = feature.getGeometry();
      let resultArray = [];
      let param = new QueryByGeometryParameters({
        queryParams: {name: "China_PreCenCity_pt@China"},
        geometry: polygon
      });
      new QueryService(this.url).queryByGeometry(param, function (serviceResult) {
        let features = serviceResult.result.recordsets[0].features.features;
        if(features!=null && features.length!=null){
          for(let i=0;i<features.length;i++){
            let feature = features[i];
            let temp = feature.properties;
            let code = temp.GNID;
            that.parentdistrictCodeList.push(code);
            let city = temp.NAME;
            //省市县名称处理
            city = that.setNameStr(city);
            that.parentdistrictNameList.push(city);
          }
        }
        //设置查询省市县是否完成参数
        that.queryCityBool = true;
        console.log("完成几何查询--市值(除省会城市)");
        //判断省市县是否查询完毕
        if(that.queryProvinceBool && that.queryCityBool && that.queryProCityBool && that.queryAreaBool && that.queryDrawAreaBool){
          //匹配省市县信息
          that.getProvinceCityArea(feature);
          //完成查询
          that.mapLoading(null);
        }
      });

      return resultArray;
    },
    queryArea(feature){//几何查询--区县值
      let that = this;
      let polygon = feature.getGeometry();
      let resultArray = [];
      let param = new QueryByGeometryParameters({
        queryParams: {name: "District_pt@China"},
        geometry: polygon
      });
      new QueryService(this.url).queryByGeometry(param, function (serviceResult) {
        let features = serviceResult.result.recordsets[0].features.features;
        if(features!=null && features.length!=null){
          for(let i=0;i<features.length;i++){
            let feature = features[i];
            let temp = feature.properties;
            let code = temp.GNID;
            that.parentdistrictCodeList.push(code);
            let area = temp.NAME;
            //省市县名称处理
            area = that.setNameStr(area);
            that.parentdistrictNameList.push(area);
          }
        }
        console.log("完成几何查询--区县值");
        //设置查询省市县是否完成参数
        that.queryAreaBool = true;
        //判断省市县是否查询完毕
        if(that.queryProvinceBool && that.queryCityBool && that.queryProCityBool && that.queryAreaBool && that.queryDrawAreaBool){
          //匹配省市县信息
          that.getProvinceCityArea(feature);
          //完成查询
          that.mapLoading(null);
        }
      });

      return resultArray;
    },
    queryDrawArea(feature,allLonLatArr){//查询绘制区域经纬度点地址
      let that = this;
      let polygon = feature.getGeometry();
      let pointArray = polygon.getCoordinates();
      let pointArr = pointArray[0];
      let i = this.queryDrawAreaPointCount;//绘制区域点数量
      if(i>=(pointArray[0].length - 1)){
        pointArr = allLonLatArr;//多边形内部均匀分布点数组
        i = this.queryDrawAreaPointCount - (pointArray[0].length - 1);//从0开始
      }
      let num = pointArray[0].length - 1 + allLonLatArr.length;
      let lonlat = pointArr[i];
      let lon = lonlat[0];
      let lat = lonlat[1];
      //设置url
      let url = "https://fxpc.mem.gov.cn/data_preparation/171dd1d5-bbb3-483a-a7f6-50d6d98cee1f/b5c55956-d1d7-4c00-8ccc-3145269327e3/reverse_geocoding?location=" + lon + "," +lat + "&geokey=94E99EB4FEB9B48CD5348F7BCF5BB620";
      //天地图数据服务获取地址--逆地理编码查询
      let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
      httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中  ps:"http://localhost:8080/rest/xxx"
      httpRequest.send();//第三步：发送请求  将请求参数写在URL中
      /**
       * 获取数据后的处理程序
       */
      httpRequest.onreadystatechange = function () {
        if (httpRequest.readyState == 4 && httpRequest.status == 200) {
          let json = httpRequest.responseText;//获取到json字符串，还需解析
          let obj = JSON.parse(json);
          console.log("地址解析");
          console.log(obj);
          //let addressComponent = obj.result.addressComponent;
          let addressComponent = obj.result.address_component;
          let code = addressComponent.adcode;
          let country = addressComponent.country;
          let province = addressComponent.province;
          let city = addressComponent.city;
          let area = addressComponent.district;
          let township = obj.result.formatted_address;
          if(obj.status=="0" && country=="中国"){
            that.parentdistrictCodeList.push(code);
            let name = province;
            if(area!=null && area!=""){
              name = area;
            }else if(city!=null && city!=""){
              name = city;
            }
            that.parentdistrictNameList.push(name);
          }else{
            console.log("error");
          }
          //设置绘制区域点数量
          that.queryDrawAreaPointCount++;
          if(that.queryDrawAreaPointCount==num){
            console.log("完成查询绘制区域经纬度点地址");
            //设置绘制区域点查询完毕参数
            that.queryDrawAreaBool = true;
            //判断省市县是否查询完毕
            if(that.queryProvinceBool && that.queryCityBool && that.queryProCityBool && that.queryAreaBool && that.queryDrawAreaBool){
              //匹配省市县信息
              that.getProvinceCityArea(feature);
              //完成查询
              that.mapLoading(null);
            }
          }else{
            that.queryDrawArea(feature,allLonLatArr);//经纬度地址解析
          }
        }else if(httpRequest.readyState == 4 && httpRequest.status == 500){
          console.log("httpRequest.readyState == 4 && httpRequest.status == 500");
          console.log(lon+","+lat);
          //设置绘制区域点数量
          that.queryDrawAreaPointCount++;
          if(that.queryDrawAreaPointCount==num){
            console.log("完成查询绘制区域经纬度点地址");
            //设置绘制区域点查询完毕参数
            that.queryDrawAreaBool = true;
            //判断省市县是否查询完毕
            if(that.queryProvinceBool && that.queryCityBool && that.queryProCityBool && that.queryAreaBool && that.queryDrawAreaBool){
              //匹配省市县信息
              that.getProvinceCityArea(feature);
              //完成查询
              that.mapLoading(null);
            }
          }else{
            that.queryDrawArea(feature,allLonLatArr);//经纬度地址解析
          }
        }
      };
    },
    //省市县名称处理
    setNameStr(str){
      if(str!=null && str!=undefined){
        let arr = str.split("\r\n ");
        str = arr.join('');
        //去除空格
        str = str.replace(/\s*/g,"");
      }

      return str;
    },
    //显示调研点列表
    showSurveyList(newVal){
      console.log("显示调研点列表");
      if(this.surveyVectorLayer!=null){
        this.surveyVectorLayer.getSource().getSource().clear();//清空
        let newVal = this.allDataList;
        console.log("数据长度："+newVal.length);
        if(newVal.length>0){
          let featureTmpArray = [];
          for(let i=0;i<newVal.length;i++){
            let longitude = newVal[i].longitude;
            let latitude = newVal[i].latitude;
            //处理经纬度
            let lonlat = this.getLonLat(longitude,latitude)
            if(lonlat!=null){
              //点
              let featureTmp = new Feature({
                geometry: new Point(lonlat)
              });
              //样式
              let style = this.getPointStyle();
              featureTmp.setStyle(style);
              //设置属性
              featureTmp.setProperties({
                id:newVal[i].id,
                taskCode:newVal[i].taskCode,
                taskName:newVal[i].taskName,
                province:newVal[i].province,
                city:newVal[i].city,
                area:newVal[i].area,
                township:newVal[i].township,
                assignorName:newVal[i].assignorName,
                fieldSurveyName:newVal[i].fieldSurveyName,
                longitude:newVal[i].longitude,
                latitude:newVal[i].latitude,
              });
              //添加抽样点
              // this.surveyVectorLayer.getSource().getSource().addFeature(featureTmp);
              featureTmpArray.push(featureTmp);
            }
          }
          //批量添加抽样点
          this.surveyVectorLayer.getSource().getSource().addFeatures(featureTmpArray);
        }
      }
    },
    clusterMarkers(){//聚合点图标
      //全部调研点图层
      this.surveyVectorLayer = new VectorLayer({
        source: new Cluster({
          distance: 40,
          minDistance: 20,
          source: new VectorSource({
            wrapX: false
          })
        }),
        projection: 'EPSG:4490',
        style: function (feature) {
          let styleCache = {};
          let size = feature.get('features').length;
          let style = styleCache[size];
          if (!style) {
            let color = size > 25 ? "192,0,0" : size > 8 ? "255,128,0" : "0,128,0";
            let radius = Math.max(8, Math.min(size * 0.75, 20));
            if(size==1){
              style = new Style({
                image: new Icon({
                  src: dingweiImg,
                  anchor: [0.5, 1]
                }),
              });
            }else{
              style = styleCache[size] = [new Style({
                image: new Circle({
                  radius: radius,
                  stroke: new Stroke({
                    color: "rgba(" + color + ",0.5)",
                    width: 15
                  }),
                  fill: new Fill({
                    color: "rgba(" + color + ",1)"
                  })
                }),
                text: new Text({
                  text: size.toString(),
                  fill: new Fill({
                    color: '#fff'
                  })
                })
              })
              ];
            }
          }
          return style;
        }
      });
      this.map.addLayer(this.surveyVectorLayer);
      this.surveyVectorLayer.setZIndex(4);
    },
    //显示隐藏调研点列表
    querySurveyList(){
      if(this.showHideSurveyBool) {
        this.getSurveyList();//查询抽样点调查列表
        this.showHideSurveyBool=false;
      }else{
        if(this.surveyVectorLayer!=null){
          this.surveyVectorLayer.getSource().getSource().clear();//清空
        }
        this.showHideSurveyBool=true;
      }
    },
    //处理经纬度
    getLonLat(longitude,latitude){
      let lonlat = null;
      if(longitude!=null && latitude!=null && longitude!="" && latitude!=""){
        let lon = Number(longitude);
        let lat = Number(latitude);
        if(lon>0 && lon<180 && lat>0 && lat<90){
          lonlat = [lon,lat];
        }
      }

      return lonlat;
    },
    //匹配省市县信息
    getProvinceCityArea(feature){
      console.log("匹配省市县信息---");
      console.log(this.parentdistrictNameList);
      console.log(this.parentdistrictCodeList);
      if(this.parentdistrictCodeList.length>0){
        let tempNamelist = [];
        let tempCodelist = [];
        let tempObjList = [];
        let list = [];//匹配省市县信息结果列表
        let codeList = [];//匹配省市县信息Code结果列表
        for(let i=0;i<this.parentdistrictCodeList.length;i++){
          let code = this.parentdistrictCodeList[i];
          let name = this.parentdistrictNameList[i];
          //name = this.getProvinceCityAreaByName(name);//根据行政区划名称获取省市区信息
          name = this.getProvinceCityAreaByCode(code);//根据行政区划编码获取省市区信息
          this.parentdistrictNameList[i] = name;
          //添加到返回结果的新建任务参数--行政区划
          if(name!=null && this.isObjInArray(tempNamelist,name)==-1){
            tempNamelist.push(name);
            tempCodelist.push(code);
            let obj = {
              name:name,
              code:Number(code)
            }
            tempObjList.push(obj);
          }
        }
        //升序排序
        function sortby(prop) {
          // prop 属性名
          // rev  升序降序 默认升序
          return function(a, b) {
            let val1 = a[prop];
            let val2 = b[prop];
            return val1 - val2;
          }
        }
        tempObjList.sort(sortby('code'));//按code升序排序
        console.log("去除重复省市县信息");
        console.log(tempObjList);
        //去除重复省市县信息
        if(tempObjList.length>0){
          let tempProvinceCodeArray = [];
          let tempCityCodeArray = [];
          //获取全部省市信息
          for(let i=0;i<tempObjList.length;i++) {
            let obj = tempObjList[i];
            let name = obj.name;
            let code = obj.code;
            code = code.toString();
            let arr = name.split("-");
            if (arr.length == 1) {//省或直辖市
              if(this.isObjInArray(tempProvinceCodeArray,code)==-1){
                console.log(name+"--省--");
                tempProvinceCodeArray.push(code);
              }
            }else if (arr.length == 2) {//市或直辖市的区县
              let tempProvince = arr[0];
              code = code.substring(0,2) + "0000";
              if(this.isObjInArray(tempProvinceCodeArray,code)==-1){
                console.log(name+"--市截取省--"+tempProvince);
                tempProvinceCodeArray.push(code);
              }
            }else if (arr.length == 3) {//区县
              let tempCity = arr[0]+"-"+arr[1];
              code = code.substring(0,4) + "00";
              if(this.isObjInArray(tempCityCodeArray,code)==-1){
                console.log(name+"--区县截取市--"+tempCity);
                tempCityCodeArray.push(code);
              }
            }
          }
          console.log("tempProvinceCodeArray");
          console.log(tempProvinceCodeArray);
          //判断省是否包含全部市，直辖市是否包含全部区县，市是否包含全部区县，合并省和市信息
          let mergeProvinceCodeArray = [];
          let mergeCityCodeArray = [];
          if(tempCityCodeArray!=null && tempCityCodeArray.length>0){
            for(let i=0;i<tempCityCodeArray.length;i++){
              let tempCityCode = tempCityCodeArray[i];
              let tempCityChildrenArray = this.getCityChildrenArrayByCode(tempCityCode);//根据市code获取children字符串列表
              console.log("tempCityChildrenArray"+tempCityCode);
              console.log(tempCityChildrenArray);
              let count = 0;
              for (let j = 0; j < tempObjList.length; j++) {
                let obj1 = tempObjList[j];
                let code1 = obj1.code;
                if(this.isObjInArray(tempCityChildrenArray,code1)!=-1){//区县
                  console.log("code1--"+code1);
                  console.log("code1--"+count);
                  count++;
                }
              }
              console.log("市是否包含全部区县,"+count+","+tempCityChildrenArray.length);
              if (count==tempCityChildrenArray.length) {//市是否包含全部区县
              //if (count>(tempCityChildrenArray.length-3)) {//市是否包含全部区县-3
                if(this.isObjInArray(mergeCityCodeArray,tempCityCode)==-1){
                  mergeCityCodeArray.push(tempCityCode);
                }
              }
            }
          }
          console.log("mergeCityCodeArray");
          console.log(mergeCityCodeArray);
          if(tempProvinceCodeArray!=null && tempProvinceCodeArray.length>0){
            for(let i=0;i<tempProvinceCodeArray.length;i++){
              let tempProvinceCode = tempProvinceCodeArray[i];
              let tempProvinceChildrenArray = this.getProvinceChildrenArrayByCode(tempProvinceCode);//根据省code获取children字符串列表
              let count = 0;
              if(tempProvinceCode=="110000" || tempProvinceCode=="120000" || tempProvinceCode=="310000" || tempProvinceCode=="500000"){
                //直辖市
                for (let j = 0; j < tempObjList.length; j++) {
                  let obj1 = tempObjList[j];
                  let code1 = obj1.code;
                  if(this.isObjInArray(tempProvinceChildrenArray,code1)!=-1){//区县
                    count++;
                  }
                }
              }else{//省
                for (let j = 0; j < mergeCityCodeArray.length; j++) {
                  let code1 = mergeCityCodeArray[j];
                  if(code1=="710100"){//台湾省-台湾省
                    code1 = "710000";
                  }
                  if(this.isObjInArray(tempProvinceChildrenArray,code1)!=-1){//市
                    console.log("code1--"+code1);
                    console.log("code1--"+count);
                    count++;
                  }
                }
              }
              console.log(count+","+tempProvinceChildrenArray.length);
              console.log(tempProvinceChildrenArray);
              if (count==tempProvinceChildrenArray.length) {//省是否包含全部市，直辖市是否包含全部区县
              //if (count>(tempProvinceChildrenArray.length-3)) {//省是否包含全部市，直辖市是否包含全部区县-3
                if(this.isObjInArray(mergeProvinceCodeArray,tempProvinceCode)==-1){
                  mergeProvinceCodeArray.push(tempProvinceCode);
                }
              }
            }
          }
          console.log("mergeProvinceCodeArray");
          console.log(mergeProvinceCodeArray);
          //添加其他未合并的区县数据
          for(let i=0;i<tempObjList.length;i++){
            let obj = tempObjList[i];
            let name = obj.name;
            let code = obj.code;
            code = code.toString();
            let arr = name.split("-");
            if (arr.length == 1) {//省
              if(this.isObjInArray(mergeProvinceCodeArray,code)!=-1 && this.isObjInArray(list,name)==-1){
                list.push(name);
                codeList.push(code);
              }
            }else if (arr.length == 2) {//市或直辖市的区县
              let tempCode = code.substring(0,2) + "0000";
              if(this.isObjInArray(mergeProvinceCodeArray,tempCode)!=-1){//判断是否市合并为省、直辖市的区县合并为直辖市
                if(this.isObjInArray(list,arr[0])==-1){
                  list.push(arr[0]);
                  codeList.push(tempCode);
                }
              }else{//不合并市或直辖市的区县
                if(this.isObjInArray(list,name)==-1){//判断是否包含
                  list.push(name);
                  codeList.push(code);
                }
              }
            }else if (arr.length == 3) {//区县
              let bool = true;
              if(list.length>0){
                for(let j=0;j<list.length;j++){
                  let temp = list[j];
                  if(name.indexOf(temp)!=-1){//判断是否包含
                    bool = false;
                    break;
                  }
                }
              }
              if(bool){
                if(this.isObjInArray(list,name)==-1){//判断是否包含
                  list.push(name);
                  codeList.push(code);
                }
              }
            }
          }
        }
        console.log("合并省市区县信息结果");
        console.log(list);
        console.log(codeList);
        this.parentdistrictList = list;
        //设置属性
        feature.setProperties({parentdistrictList:this.parentdistrictList});
      }
      //设置参数
      this.queryProvinceBool=false;
      this.queryCityBool=false;
      this.queryProCityBool=false;
      this.queryAreaBool=false;
      this.queryDrawAreaBool = false;
      this.queryDrawAreaPointCount = 0;
    },
    getProvinceCityAreaByName(name){//根据行政区划名称获取省市区信息
      //根节点ID
      let rootPid = "af50c20a9b9f474e88dbbf742a7e5377";
      //获取行政区划树列表
      let treeList = this.districtTreeDataList;
      if(treeList!=null && treeList.length>0){
        for(let i=0;i<treeList.length;i++){
          let provinceData = treeList[i];//省节点
          if(provinceData!=null){
            let provinceName = provinceData.name;//省
            if(name==provinceName){
              return provinceName;
            }
            let cityList = provinceData.children;//市列表
            if(cityList!=null){
              for(let j=0;j<cityList.length;j++){
                let cityData = cityList[j];
                if(cityData!=null){
                  let cityName = cityData.name;//市
                  if(name==cityName){
                    return provinceName+"-"+cityName;
                  }
                  let areaList = cityData.children;//区县列表
                  if(areaList!=null){
                    for(let j=0;j<areaList.length;j++){
                      let areaData = areaList[j];
                      if(areaData!=null){
                        let areaName = areaData.name;//区县
                        if(name==areaName){
                          return provinceName+"-"+cityName+"-"+areaName;
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      console.log("查询不到："+name);
      return null;
    },
    getProvinceCityAreaByCode(code){//根据行政区划编码获取省市区信息
      //根节点ID
      let rootPid = "1";
      if(this.districtTreeDataList!=null && this.districtTreeDataList!=""){
        //获取行政区划树列表
        let treeList = this.districtTreeDataList;
        if(treeList!=null && treeList.length>0){
          for(let i=0;i<treeList.length;i++){
            let provinceData = treeList[i];//省节点
            if(provinceData!=null){
              let provinceName = provinceData.name;//省
              let provinceCode = provinceData.code;//省编码
              if(code==provinceCode){
                return provinceName;
              }
              let cityList = provinceData.children;//市列表
              if(cityList!=null){
                for(let j=0;j<cityList.length;j++){
                  let cityData = cityList[j];
                  if(cityData!=null){
                    let cityName = cityData.name;//市
                    let cityCode = cityData.code;//市编码
                    if(code==cityCode){
                      return provinceName+"-"+cityName;
                    }
                    let areaList = cityData.children;//区县列表
                    if(areaList!=null){
                      for(let j=0;j<areaList.length;j++){
                        let areaData = areaList[j];
                        if(areaData!=null){
                          let areaName = areaData.name;//区县
                          let areaCode = areaData.code;//区县编码
                          if(code==areaCode){
                            return provinceName+"-"+cityName+"-"+areaName;
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      console.log("查询不到code："+code);
      return null;
    },
    getAreaByCode(code,name){//根据行政区划编码获取省市区面积信息
      //根节点ID
      let rootPid = "1";
      let area = 0;
      if(this.districtTreeDataList!=null && this.districtTreeDataList!=""){
        //获取行政区划树列表
        let treeList = this.districtTreeDataList;
        if(treeList!=null && treeList.length>0){
          for(let i=0;i<treeList.length;i++){
            let provinceData = treeList[i];//省节点
            if(provinceData!=null){
              let provinceName = provinceData.name;//省
              let provinceCode = provinceData.code;//省编码
              if(code==null && name==provinceName){
                let cityList = provinceData.children;//市列表
                if(cityList!=null){
                  for(let j=0;j<cityList.length;j++){
                    let cityData = cityList[j];
                    if(cityData!=null){
                      let cityName = cityData.name;//市
                      let cityCode = cityData.code;//市编码
                      let areaList = cityData.children;//区县列表
                      if(areaList!=null){
                        for(let j=0;j<areaList.length;j++){
                          let areaData = areaList[j];
                          if(areaData!=null){
                            let areaName = areaData.name;//区县
                            let areaCode = areaData.code;//区县编码
                            area += areaData.area / 1000000;//平方公里
                          }
                        }
                      }
                    }
                  }
                }
                return area;
              }
              let cityList = provinceData.children;//市列表
              if(cityList!=null){
                for(let j=0;j<cityList.length;j++){
                  let cityData = cityList[j];
                  if(cityData!=null){
                    let cityName = cityData.name;//市
                    let cityCode = cityData.code;//市编码
                    if(code==cityCode){
                      let areaList = cityData.children;//区县列表
                      if(areaList!=null){
                        for(let j=0;j<areaList.length;j++){
                          let areaData = areaList[j];
                          if(areaData!=null){
                            let areaName = areaData.name;//区县
                            let areaCode = areaData.code;//区县编码
                            area += areaData.area / 1000000;//平方公里
                          }
                        }
                      }
                      return area;
                    }
                    let areaList = cityData.children;//区县列表
                    if(areaList!=null){
                      for(let j=0;j<areaList.length;j++){
                        let areaData = areaList[j];
                        if(areaData!=null){
                          let areaName = areaData.name;//区县
                          let areaCode = areaData.code;//区县编码
                          if(code==areaCode){
                            area += areaData.area / 1000000;//平方公里
                            return area;
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
      console.log("查询不到code："+code);
      return area;
    },
    getProvinceCodeByName(name){//根据省名称获取省编码信息
      //获取行政区划树列表
      let treeList = this.districtTreeDataList;
      if(treeList!=null && treeList.length>0){
        for(let i=0;i<treeList.length;i++){
          let provinceData = treeList[i];//省节点
          if(provinceData!=null){
            let provinceName = provinceData.name;//省
            if(name==provinceName){
              let provinceCode = provinceData.code;//省编码
              return provinceCode;
            }
          }
        }
      }
      console.log("查询不到："+name);
      return null;
    },
    getProvinceChildrenArrayByCode(code){//根据省code获取市code列表，根据直辖市code获取区县code列表
      let childrenArray = [];
      //获取行政区划树列表
      let treeList = this.districtTreeDataList;
      if(treeList!=null && treeList.length>0){
        for(let i=0;i<treeList.length;i++){
          let provinceData = treeList[i];//省节点
          if(provinceData!=null){
            let provinceCode = provinceData.code;//省编码
            if(code==provinceCode){
              let cityList = provinceData.children;//市列表
              if(cityList!=null){
                for(let j=0;j<cityList.length;j++){
                  let cityData = cityList[j];
                  if(cityData!=null){
                    let cityCode = cityData.code;//市编码
                    childrenArray.push(cityCode);
                  }
                }
              }
            }
          }
        }
      }
      if(childrenArray.length>0){
        console.log("ProvinceChildrenArray："+childrenArray);
      }else{
        console.log("查询不到ProvinceChildrenArray："+code);
      }
      return childrenArray;
    },
    getCityChildrenArrayByCode(code){//根据市code获取区县code列表
      let childrenArray = [];
      //获取行政区划树列表
      let treeList = this.districtTreeDataList;
      if(treeList!=null && treeList.length>0){
        for(let i=0;i<treeList.length;i++){
          let provinceData = treeList[i];//省节点
          if(provinceData!=null){
            let cityList = provinceData.children;//市列表
            if(cityList!=null){
              for(let j=0;j<cityList.length;j++){
                let cityData = cityList[j];
                if(cityData!=null){
                  let cityCode = cityData.code;//市编码
                  if(cityCode=="710000"){//台湾省-台湾省
                    cityCode = "710100";
                  }
                  if(code==cityCode){
                    let areaList = cityData.children;//区县列表
                    if(areaList!=null){
                      for(let j=0;j<areaList.length;j++){
                        let areaData = areaList[j];
                        if(areaData!=null){
                          let areaName = areaData.name;//区县
                          let areaCode = areaData.code;//区县编码
                          childrenArray.push(areaCode);
                        }
                      }
                    }
                    break;
                  }
                }
              }
            }
          }
        }
      }
      if(childrenArray.length>0){
        console.log("CityChildrenArray："+childrenArray);
      }else{
        console.log("查询不到CityChildrenArray："+code);
      }
      return childrenArray;
    },
    getCodeByAllName(allName){//根据所有省市县全名字符串获取codelist
      let allCodeList = [];
      if(allName!=null && allName!=""){
        let array = allName.split("、");
        //获取行政区划树列表
        let treeList = this.districtTreeDataList;
        for(let i=0;i<array.length;i++){
          let name = array[i];
          let code = null;
          let arr = name.split('-');
          if(arr.length==1){//省或直辖市
            if(treeList!=null && treeList.length>0){
              for(let i=0;i<treeList.length;i++){
                let provinceData = treeList[i];//省节点
                if(provinceData!=null){
                  let provinceName = provinceData.name;//省
                  if(name==provinceName){
                    let provinceCode = provinceData.code;//省编码
                    code = provinceCode;
                    break;
                  }
                }
              }
            }
          }else if(arr.length==2){//市或直辖市的区县
            if(treeList!=null && treeList.length>0){
              for(let i=0;i<treeList.length;i++){
                let provinceData = treeList[i];//省节点
                if(provinceData!=null){
                  let provinceName = provinceData.name;//省
                  if(arr[0]==provinceName){
                    let bool = false;
                    let cityList = provinceData.children;//市列表
                    if(cityList!=null){
                      for(let j=0;j<cityList.length;j++){
                        let cityData = cityList[j];
                        if(cityData!=null){
                          let cityName = cityData.name;//市
                          if(arr[1]==cityName){
                            let cityCode = cityData.code;//市编码
                            code = cityCode;
                            bool = true;
                            break;
                          }
                        }
                      }
                    }
                    if(bool){
                      break;
                    }
                  }
                }
              }
            }
          }else if(arr.length==3){//区县
            if(treeList!=null && treeList.length>0){
              for(let i=0;i<treeList.length;i++){
                let provinceData = treeList[i];//省节点
                let bool = false;
                if(provinceData!=null){
                  let provinceName = provinceData.name;//省
                  if(arr[0]==provinceName){
                    let cityList = provinceData.children;//市列表
                    if(cityList!=null){
                      for(let j=0;j<cityList.length;j++){
                        let cityData = cityList[j];
                        if(cityData!=null){
                          let cityName = cityData.name;//市
                          if(arr[1]==cityName){
                            let areaList = cityData.children;//区县列表
                            if(areaList!=null){
                              for(let j=0;j<areaList.length;j++){
                                let areaData = areaList[j];
                                if(areaData!=null){
                                  let areaName = areaData.name;//区县
                                  if(arr[2]==areaName){
                                    let areaCode = areaData.code;//区县编码
                                    code = areaCode;
                                    bool = true;
                                    break;
                                  }
                                }
                              }
                            }
                            if(bool){
                              break;
                            }
                          }
                        }
                      }
                    }
                  }
                }
                if(bool){
                  break;
                }
              }
            }
          }
          //添加code
          allCodeList.push(code);
        }
      }

      return allCodeList;
    },
    isObjInArray(array,obj){//判断数组中是否包含对象
      let index = -1;
      if(array!=null && array.length>0){
        for(let i=0;i<array.length;i++){
          if(obj==array[i]){
            index = i;
            break;
          }
        }
      }
      return index;
    },
    getPolygonExtentPoints(polygon){//获取多边形面内的均匀点分布数组
      console.log("获取多边形面内的均匀点分布数组");
      let extent = polygon.getExtent();
      console.log(extent);
      let lon1 = extent[0];
      let lat1 = extent[1];
      let lon2 = extent[2];
      let lat2 = extent[3];
      let num = 0;//取num位小数--默认取整
      if(Math.abs(lon1-lon2)<1 || Math.abs(lat1-lat2)<1){
        num = 1;//取num位小数
      }
      let temp = Math.pow(10,num);
      console.log(temp);
      //左下角经纬度--向上取整
      let tempLon1 = Math.ceil(lon1*temp);
      let tempLat1 = Math.ceil(lat1*temp);
      //右上角经纬度--向下取整
      let tempLon2 = Math.floor(lon2*temp);
      let tempLat2 = Math.floor(lat2*temp);
      console.log(tempLon1+","+tempLat1+";"+tempLon2+","+tempLat2);
      let allLonLatArr = [];
      if(tempLon1<tempLon2 && tempLat1<tempLat2){
        console.log("tempLon1<tempLon2 && tempLat1<tempLat2");
        for(let i=tempLon1;i<=tempLon2;i++){
          for(let j=tempLat1;j<=tempLat2;j++){
            let lonlat = [i/temp,j/temp];
            //判断点是否在面内
            let bool = polygon.intersectsCoordinate(lonlat);
            if(bool){
              allLonLatArr.push(lonlat);
            }
          }
        }
      }else if(tempLon1<tempLon2){
        console.log("tempLon1<tempLon2");
        for(let i=tempLon1;i<=tempLon2;i++){
          let lonlat = [i/temp,lat1];
          //判断点是否在面内
          let bool = polygon.intersectsCoordinate(lonlat);
          if(bool){
            allLonLatArr.push(lonlat);
          }
        }
      }else if(tempLat1<tempLat2){
        console.log("tempLat1<tempLat2");
        for(let j=tempLat1;j<=tempLat2;j++){
          let lonlat = [lon1,j/temp];
          //判断点是否在面内
          let bool = polygon.intersectsCoordinate(lonlat);
          if(bool){
            allLonLatArr.push(lonlat);
          }
        }
      }else{
        console.log("else");
        //取中心点
        let lon = (lon1+lon2)/2;
        let lat = (lat1+lat2)/2;
        let lonlat = [lon,lat];
        allLonLatArr.push(lonlat);
      }
      console.log("获取多边形每条边的中心点");
      //获取多边形每条边的中心点
      let pointArray = polygon.getCoordinates();
      let pointArr = pointArray[0];
      for(let i=0;i<(pointArr.length-1);i++){
        let lonlat0 = pointArr[i];
        let lonlat1 = pointArr[i+1];
        let lon = (lonlat0[0] + lonlat1[0])/2;
        let lat = (lonlat0[1] + lonlat1[1])/2;
        let lonlat = [lon,lat];
        console.log(lonlat);
        allLonLatArr.push(lonlat);
      }
      console.log("allLonLatArr:");
      console.log(allLonLatArr);

      return allLonLatArr;
    },
    queryDrawAreaNew(feature){//新查询绘制区域经纬度任务地区
      this.drawAreaFeature = feature;//地图圈选要素
      let polygon = feature.getGeometry();
      let pointArray = polygon.getCoordinates();
      let pointArr = pointArray[0];
      let geomText = "";
      if(pointArr!=null && pointArr.length>0){
        geomText = "MULTIPOLYGON(((";
        for(let i=0;i<pointArr.length;i++){
          let lonlat = pointArr[i];
          if(i>0){
            geomText += ",";
          }
          geomText += lonlat[0] + ' ' + lonlat[1];
        }
        geomText += ")))";
        //根据地图圈选区域，查询行政区划--省|市|区县的名称和code列表
        this.$emit("queryTaskRegionNameCodeListByGeomText",geomText);
      }
    },
    queryDrawAreaNewResult(list){//完成查询绘制区域经纬度任务地区
      if(this.drawAreaFeature!=null){
        console.log("完成查询绘制区域经纬度任务地区");
        if(list!=null && list.length==2){
          let nameList = list[0];//行政区划名称列表
          let codeList = list[1];//行政区划编码列表
          for(let i=0;i<nameList.length;i++){
            let nameArr = nameList[i].split("-");
            let codeArr = codeList[i].split("-");
            for(let j=0;j<nameArr.length;j++){
              let name = nameArr[j];
              let code = codeArr[j];
              if(code!=null && this.isObjInArray(this.parentdistrictCodeList,code)==-1){
                this.parentdistrictCodeList.push(code);
                this.parentdistrictNameList.push(name);
              }
            }
          }
        }
        //设置绘制区域点查询完毕参数
        this.queryDrawAreaBool = true;
        //匹配省市县信息
        this.getProvinceCityArea(this.drawAreaFeature);
        //完成查询
        this.mapLoading(null);
      }
    },
    importShpTxtWktGeom(geomText){//导入任务区域
      this.source.clear();//清空
      this.shpTxtWktGeom = geomText;
      //空间数据
      let featureTmp = new WKT().readFeature(geomText);
      let geometry = featureTmp.getGeometry();
      this.showHideDrawTaskBool = false;//停止地图圈选工作区域
      //设置样式
      let style = this.getPolyonStyle("red");
      featureTmp.setStyle(style);
      let area = getPolygonArea(geometry);
      //设置属性
      featureTmp.setProperties({area: area,type:"导入任务区域"});
      //清空查询行政区划列表
      this.parentdistrictList = [];
      //清空区域查询行政区划名称列表
      this.parentdistrictNameList = [];
      //清空区域查询行政区划编码列表
      this.parentdistrictCodeList = [];
      //正在查询
      this.mapLoading("正在查询，请稍候...");
      this.drawAreaFeature = featureTmp;
      //根据地图圈选区域，查询行政区划--省|市|区县的名称和code列表
      this.$emit("queryTaskRegionNameCodeListByGeomText",geomText);
      this.source.addFeature(featureTmp);
      this.showFeatureBoundingExtent(featureTmp);//缩放到要素区域位置

      //计算面积
      function getPolygonArea (polygon) {
        // 这里一定要给坐标，和地图坐标保持一致，否则面积不准
        const area = getArea(polygon, {projection: 'EPSG:4490'})
        let output = Math.round((area / 1000000) * 100) / 100;//平方公里
        return output;
      }
    },
    showFeatureBoundingExtent(feature) {//缩放到要素区域位置
      //全部经纬度
      let allCoordinates = [];
      //获取范围
      let extent = feature.getGeometry().getExtent();
      if(extent.length==4){
        //全部经纬度--左下角
        allCoordinates.push([extent[0],extent[1]]);
        //全部经纬度--右上角
        allCoordinates.push([extent[2],extent[3]]);
      }
      this.showBoundingExtent(allCoordinates);//缩放到区域位置
    },
    showBoundingExtent(coordinates){//缩放到区域位置
      console.log("缩放到区域位置");
      if (coordinates!=null && coordinates.length > 1) {
        const extent = boundingExtent(coordinates);
        //this.map.getView().fit(extent, {duration: 1000, padding: [50, 50, 50, 50]});
        this.map.getView().fit(extent, {padding: [50, 50, 50, 50]});
        //获取默认位置
        // this.center = this.map.getView().getCenter();
        // this.zoom = this.map.getView().getZoom();
      }
    },
  }
}

</script>

<style scoped>

</style>